{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1.1. Introducing IPython and the Jupyter Notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "podoc": {
     "output_text": "Screenshot of a Jupyter notebook"
    },
    "ExecuteTime": {
     "end_time": "2023-10-20T12:43:51.510669Z",
     "start_time": "2023-10-20T12:43:51.490306Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello world!\n"
     ]
    }
   ],
   "source": [
    "print(\"Hello world!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:43:51.511723Z",
     "start_time": "2023-10-20T12:43:51.493816Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "4"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 + 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:43:51.511927Z",
     "start_time": "2023-10-20T12:43:51.497943Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "12"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "_ * 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:43:51.655987Z",
     "start_time": "2023-10-20T12:43:51.501403Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "01_notebook.ipynb 03_numpy.ipynb    05_config.ipynb\r\n",
      "02_pandas.ipynb   04_magic.ipynb    06_kernel.ipynb\r\n"
     ]
    }
   ],
   "source": [
    "!ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:43:51.656668Z",
     "start_time": "2023-10-20T12:43:51.646918Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "Available line magics:\n%alias  %alias_magic  %autoawait  %autocall  %automagic  %autosave  %bookmark  %cat  %cd  %clear  %code_wrap  %colors  %conda  %config  %connect_info  %cp  %debug  %dhist  %dirs  %doctest_mode  %ed  %edit  %env  %gui  %hist  %history  %killbgscripts  %ldir  %less  %lf  %lk  %ll  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %lx  %macro  %magic  %man  %matplotlib  %mkdir  %more  %mv  %notebook  %page  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %pip  %popd  %pprint  %precision  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %qtconsole  %quickref  %recall  %rehashx  %reload_ext  %rep  %rerun  %reset  %reset_selective  %rm  %rmdir  %run  %save  %sc  %set_env  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode\n\nAvailable cell magics:\n%%!  %%HTML  %%SVG  %%bash  %%capture  %%code_wrap  %%debug  %%file  %%html  %%javascript  %%js  %%latex  %%markdown  %%perl  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%script  %%sh  %%svg  %%sx  %%system  %%time  %%timeit  %%writefile\n\nAutomagic is ON, % prefix IS NOT needed for line magics.",
      "application/json": {
       "line": {
        "automagic": "AutoMagics",
        "autocall": "AutoMagics",
        "alias_magic": "BasicMagics",
        "lsmagic": "BasicMagics",
        "magic": "BasicMagics",
        "page": "BasicMagics",
        "pprint": "BasicMagics",
        "colors": "BasicMagics",
        "xmode": "BasicMagics",
        "quickref": "BasicMagics",
        "doctest_mode": "BasicMagics",
        "gui": "BasicMagics",
        "precision": "BasicMagics",
        "notebook": "BasicMagics",
        "save": "CodeMagics",
        "pastebin": "CodeMagics",
        "loadpy": "CodeMagics",
        "load": "CodeMagics",
        "edit": "KernelMagics",
        "config": "ConfigMagics",
        "prun": "ExecutionMagics",
        "pdb": "ExecutionMagics",
        "debug": "ExecutionMagics",
        "tb": "ExecutionMagics",
        "run": "ExecutionMagics",
        "timeit": "ExecutionMagics",
        "time": "ExecutionMagics",
        "macro": "ExecutionMagics",
        "code_wrap": "ExecutionMagics",
        "load_ext": "ExtensionMagics",
        "unload_ext": "ExtensionMagics",
        "reload_ext": "ExtensionMagics",
        "history": "HistoryMagics",
        "recall": "HistoryMagics",
        "rerun": "HistoryMagics",
        "logstart": "LoggingMagics",
        "logstop": "LoggingMagics",
        "logoff": "LoggingMagics",
        "logon": "LoggingMagics",
        "logstate": "LoggingMagics",
        "pinfo": "NamespaceMagics",
        "pinfo2": "NamespaceMagics",
        "pdef": "NamespaceMagics",
        "pdoc": "NamespaceMagics",
        "psource": "NamespaceMagics",
        "pfile": "NamespaceMagics",
        "psearch": "NamespaceMagics",
        "who_ls": "NamespaceMagics",
        "who": "NamespaceMagics",
        "whos": "NamespaceMagics",
        "reset": "NamespaceMagics",
        "reset_selective": "NamespaceMagics",
        "xdel": "NamespaceMagics",
        "alias": "OSMagics",
        "unalias": "OSMagics",
        "rehashx": "OSMagics",
        "pwd": "OSMagics",
        "cd": "OSMagics",
        "env": "OSMagics",
        "set_env": "OSMagics",
        "pushd": "OSMagics",
        "popd": "OSMagics",
        "dirs": "OSMagics",
        "dhist": "OSMagics",
        "sc": "OSMagics",
        "sx": "OSMagics",
        "system": "OSMagics",
        "bookmark": "OSMagics",
        "pycat": "OSMagics",
        "pip": "PackagingMagics",
        "conda": "PackagingMagics",
        "matplotlib": "PylabMagics",
        "pylab": "PylabMagics",
        "killbgscripts": "ScriptMagics",
        "autoawait": "AsyncMagics",
        "ed": "Other",
        "hist": "Other",
        "rep": "Other",
        "clear": "KernelMagics",
        "less": "KernelMagics",
        "more": "KernelMagics",
        "man": "KernelMagics",
        "connect_info": "KernelMagics",
        "qtconsole": "KernelMagics",
        "autosave": "KernelMagics",
        "mkdir": "Other",
        "rmdir": "Other",
        "mv": "Other",
        "rm": "Other",
        "cp": "Other",
        "cat": "Other",
        "ls": "Other",
        "ll": "Other",
        "lf": "Other",
        "lk": "Other",
        "ldir": "Other",
        "lx": "Other",
        "store": "StoreMagics"
       },
       "cell": {
        "js": "DisplayMagics",
        "javascript": "DisplayMagics",
        "latex": "DisplayMagics",
        "svg": "DisplayMagics",
        "html": "DisplayMagics",
        "markdown": "DisplayMagics",
        "prun": "ExecutionMagics",
        "debug": "ExecutionMagics",
        "timeit": "ExecutionMagics",
        "time": "ExecutionMagics",
        "capture": "ExecutionMagics",
        "code_wrap": "ExecutionMagics",
        "sx": "OSMagics",
        "system": "OSMagics",
        "!": "OSMagics",
        "writefile": "OSMagics",
        "script": "ScriptMagics",
        "sh": "Other",
        "bash": "Other",
        "perl": "Other",
        "ruby": "Other",
        "python": "Other",
        "python2": "Other",
        "python3": "Other",
        "pypy": "Other",
        "SVG": "Other",
        "HTML": "Other",
        "file": "Other"
       }
      }
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%lsmagic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:43:51.657335Z",
     "start_time": "2023-10-20T12:43:51.653589Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Writing test.txt\n"
     ]
    }
   ],
   "source": [
    "%%writefile test.txt\n",
    "Hello world!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:43:51.666319Z",
     "start_time": "2023-10-20T12:43:51.657932Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello world!\n"
     ]
    }
   ],
   "source": [
    "# Let's check what this file contains.\n",
    "with open('test.txt', 'r') as f:\n",
    "    print(f.read())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "podoc": {
     "output_text": "Screenshot of the pager"
    },
    "ExecuteTime": {
     "end_time": "2023-10-20T12:43:51.701400Z",
     "start_time": "2023-10-20T12:43:51.660642Z"
    }
   },
   "outputs": [],
   "source": [
    "%run?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:43:51.701720Z",
     "start_time": "2023-10-20T12:43:51.664469Z"
    }
   },
   "outputs": [],
   "source": [
    "from IPython.display import HTML, SVG, YouTubeVideo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "podoc": {
     "output_text": "<IPython.core.display.HTML object>"
    },
    "ExecuteTime": {
     "end_time": "2023-10-20T12:43:51.703685Z",
     "start_time": "2023-10-20T12:43:51.670231Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "<IPython.core.display.HTML object>",
      "text/html": "\n<table style=\"border: 2px solid black;\">\n<tr><td>0,0</td><td>0,1</td><td>0,2</td><td>0,3</td><td>0,4</td></tr><tr><td>1,0</td><td>1,1</td><td>1,2</td><td>1,3</td><td>1,4</td></tr><tr><td>2,0</td><td>2,1</td><td>2,2</td><td>2,3</td><td>2,4</td></tr><tr><td>3,0</td><td>3,1</td><td>3,2</td><td>3,3</td><td>3,4</td></tr><tr><td>4,0</td><td>4,1</td><td>4,2</td><td>4,3</td><td>4,4</td></tr>\n</table>\n"
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "HTML('''\n",
    "<table style=\"border: 2px solid black;\">\n",
    "''' +\n",
    "     ''.join(['<tr>' +\n",
    "              ''.join([f'<td>{row},{col}</td>'\n",
    "                       for col in range(5)]) +\n",
    "              '</tr>' for row in range(5)]) +\n",
    "     '''\n",
    "</table>\n",
    "''')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "podoc": {
     "output_text": "<IPython.core.display.SVG object>"
    },
    "ExecuteTime": {
     "end_time": "2023-10-20T12:43:51.836094Z",
     "start_time": "2023-10-20T12:43:51.673326Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "<IPython.core.display.SVG object>",
      "image/svg+xml": "<svg width=\"600\" height=\"80\"><circle cx=\"300\" cy=\"30\" r=\"0.0\" fill=\"red\" stroke-width=\"2\" stroke=\"black\">\n        </circle><circle cx=\"297\" cy=\"30\" r=\"3.0\" fill=\"red\" stroke-width=\"2\" stroke=\"black\">\n        </circle><circle cx=\"288\" cy=\"30\" r=\"6.0\" fill=\"red\" stroke-width=\"2\" stroke=\"black\">\n        </circle><circle cx=\"273\" cy=\"30\" r=\"9.0\" fill=\"red\" stroke-width=\"2\" stroke=\"black\">\n        </circle><circle cx=\"252\" cy=\"30\" r=\"12.0\" fill=\"red\" stroke-width=\"2\" stroke=\"black\">\n        </circle><circle cx=\"225\" cy=\"30\" r=\"15.0\" fill=\"red\" stroke-width=\"2\" stroke=\"black\">\n        </circle><circle cx=\"192\" cy=\"30\" r=\"18.0\" fill=\"red\" stroke-width=\"2\" stroke=\"black\">\n        </circle><circle cx=\"153\" cy=\"30\" r=\"21.0\" fill=\"red\" stroke-width=\"2\" stroke=\"black\">\n        </circle><circle cx=\"108\" cy=\"30\" r=\"24.0\" fill=\"red\" stroke-width=\"2\" stroke=\"black\">\n        </circle><circle cx=\"57\" cy=\"30\" r=\"27.0\" fill=\"red\" stroke-width=\"2\" stroke=\"black\">\n        </circle></svg>"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "SVG('''<svg width=\"600\" height=\"80\">''' +\n",
    "    ''.join([f'''<circle\n",
    "              cx=\"{(30 + 3*i) * (10 - i)}\"\n",
    "              cy=\"30\"\n",
    "              r=\"{3. * float(i)}\"\n",
    "              fill=\"red\"\n",
    "              stroke-width=\"2\"\n",
    "              stroke=\"black\">\n",
    "        </circle>''' for i in range(10)]) +\n",
    "    '''</svg>''')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "podoc": {
     "output_text": "<IPython.lib.display.YouTubeVideo at 0x7fc0000b64a8>"
    },
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:06.748091Z",
     "start_time": "2023-10-20T12:43:51.678375Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "<IPython.lib.display.YouTubeVideo at 0x103c5dc70>",
      "text/html": "\n        <iframe\n            width=\"400\"\n            height=\"300\"\n            src=\"https://www.youtube.com/embed/VQBZ2MqWBZI\"\n            frameborder=\"0\"\n            allowfullscreen\n            \n        ></iframe>\n        "
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "YouTubeVideo('VQBZ2MqWBZI')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```json\n",
    "{\n",
    " \"cells\": [\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 1,\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"name\": \"stdout\",\n",
    "     \"output_type\": \"stream\",\n",
    "     \"text\": [\n",
    "      \"Hello world!\\n\"\n",
    "     ]\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"print(\\\"Hello world!\\\")\"\n",
    "   ]\n",
    "  }\n",
    " ],\n",
    " \"metadata\": {},\n",
    " \"nbformat\": 4,\n",
    " \"nbformat_minor\": 2\n",
    "}\n",
    "```"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "python3",
   "language": "python",
   "display_name": "Python 3 (ipykernel)"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
